package cn.zhangjie.delay;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
import java.util.Date;

public class Producer {


    public static void main(String[] args) throws Exception {
        //1.创建生产者对象，指定生产者组名
        DefaultMQProducer Producer = new DefaultMQProducer("delay-producer-group");
        //2.连接mq
        Producer.setNamesrvAddr("localhost:9876");
        //3.启动
        Producer.start();
        //4.创建消息，设置消息对象
        Message message = new Message("delay", "hello", "我要回家".getBytes(StandardCharsets.UTF_8));
        //设置延迟登记为3级
        message.setDelayTimeLevel(3);
        System.out.println(new Date().toLocaleString());
        SendResult send = Producer.send(message);
        System.out.println(send);
        //5.关闭
        Producer.shutdown();

    }
}
